// 简易登录与用户信息 Mock（最最简单版本）

// 内置几个测试账号
const users = [
  { phone: 'Super', password: '123456', roles: ['R_SUPER'], userId: 1, email: 'super@example.com' },
  { phone: 'Admin', password: '123456', roles: ['R_ADMIN'], userId: 2, email: 'admin@example.com' },
  { phone: 'User', password: '123456', roles: ['R_USER'], userId: 3, email: 'user@example.com' }
]

// 简单的内存 token 存储（演示用）
const tokenStore = new Map<string, string>()

function createToken(userName: string) {
  const token = `mock-token-${userName}-${Date.now()}`
  const refreshToken = `mock-refresh-${userName}-${Date.now()}`
  tokenStore.set(token, userName)
  return { token, refreshToken }
}

// 登录：校验账号密码
export async function mockLogin(
  params: Api.Auth.LoginParams
): Promise<Http.BaseResponse<Api.Auth.LoginResponse>> {
  const { userName, password } = params || { phone: '', password: '' }
  const user = users.find((u) => u.phone === userName && u.password === password)

  if (!user) {
    return {
      code: 401,
      msg: '账号或密码错误',
      data: { token: '', refreshToken: '' }
    }
  }

  const { token, refreshToken } = createToken(user.phone)
  return {
    code: 200,
    msg: '登录成功',
    data: { token, refreshToken }
  }
}

// 获取用户信息：根据 token 返回固定信息
export async function mockGetUserInfo(
  token: string
): Promise<Http.BaseResponse<Api.Auth.UserInfo>> {
  const userName = tokenStore.get(token)
  const user = users.find((u) => u.phone === userName)

  if (!user) {
    return {
      code: 401,
      msg: '未授权或 token 无效',
      data: {
        buttons: [],
        roles: [],
        userId: 0,
        userName: '',
        email: ''
      }
    }
  }

  return {
    code: 200,
    msg: '获取成功',
    data: {
      buttons: [],
      roles: user.roles,
      userId: user.userId,
      userName: user.phone,
      email: user.email,
      avatar: ''
    }
  }
}

// 获取工作台的学校整体数据
export async function mockGetSchoolTotal() {
  return {
    code: 200,
    msg: '获取成功',
    data: {
      studentChange: [
        {
          id: 1,
          title: '销售产品',
          count: 1000,
          description: '2025届已落实总人数',
          icon: '&#xe812;',
          iconColor: 'rgb(var(--art-primary))',
          iconSize: 20,
          iconBgColor: 'rgb(var(--art-info))',
          textColor: 'rgb(var(--art-primary))',
          backgroundColor: 'rgb(var(--art-bg-primary))',
          showArrow: false
        },
        {
          id: 2,
          title: '活跃用户',
          count: 138,
          description: '落实困难人数',
          icon: '&#xe724;',
          iconColor: 'rgb(var(--art-warning))',
          iconSize: 20,
          iconBgColor: 'rgb(var(--art-success))',
          textColor: 'rgb(var(--art-warning))',
          backgroundColor: 'rgb(var(--art-bg-warning))',
          showArrow: false
        },
        {
          id: 3,
          title: '总收入',
          count: 32,
          description: '周增落实人数',
          icon: '&#xe70e;',
          iconColor: 'rgb(var(--art-secondary))',
          iconSize: 20,
          iconBgColor: 'rgb(var(--art-secondary))',
          textColor: 'rgb(var(--art-secondary))',
          backgroundColor: 'rgb(var(--art-bg-secondary))',
          showArrow: false
        },
        {
          id: 4,
          title: '客户评价',
          count: 75,
          description: '当前落实率',
          icon: '&#xe82d;',
          iconColor: 'rgb(var(--art-error))',
          iconSize: 20,
          iconBgColor: 'rgb(var(--art-error))',
          textColor: 'rgb(var(--art-error))',
          backgroundColor: 'rgb(var(--art-bg-error))',
          showArrow: false
        }
      ],
      weeklyPlacedDate: ['04-18', '04-18', '04-18', '04-18', '04-18', '04-18', '04-18'],
      weeklyPlacedCount: [28, 45, 82, 35, 100, 32, 55],
      weeklyPlacedYear: '2025',
      placedCategory: [
        { value: 1205, name: '未落实' },
        { value: 820, name: '升学' },
        { value: 2120, name: '就业' },
        { value: 120, name: '创业' }
      ],
      employmentRegion: [
        { value: 205, name: '北京' },
        { value: 520, name: '杭州' },
        { value: 220, name: '上海' },
        { value: 20, name: '深圳' },
        { value: 420, name: '其他' }
      ],
      employmentIndustry: [
        { value: 1205, name: '计算机' },
        { value: 820, name: '推销' },
        { value: 2120, name: '管理' },
        { value: 120, name: '研发' },
        { value: 120, name: '技术' },
        { value: 120, name: '咨询' },
        { value: 120, name: '服务业' }
      ],
      employmentOccupation: [
        { value: 125, name: '程序员' },
        { value: 810, name: '人事' },
        { value: 320, name: '管理' },
        { value: 720, name: '经销' }
      ],
      systemMessage: [
        //success为绿色——职规，空为蓝色——职规，warning为橙色——预警，danger为红色——警告
        {
          id: 1,
          title: '2025届毕业生就业数据已更新',
          time: '2小时前',
          tag: 'success',
          path: '/employment/data'
        },
        { id: 2, title: '系统维护通知', time: '昨天', tag: 'warning', path: '/employment/data' },
        { id: 3, title: '新的数据导入模板已发布', time: '前天', tag: '', path: '/employment/data' },
        {
          id: 4,
          title: '就业统计功能优化完成',
          time: '3天前',
          tag: 'danger',
          path: '/employment/data'
        },
        {
          id: 5,
          title: '学生档案填写提醒',
          time: '一周前',
          tag: 'success',
          path: '/employment/data'
        },
        {
          id: 6,
          title: '教师档案填写提醒',
          time: '一周前',
          tag: 'success',
          path: '/employment/data'
        },
        { id: 7, title: '更新通知', time: '一周前', tag: 'warning', path: '/employment/data' }
      ]
    }
  }
}

// 获取学生画像：返回男女生人数
export async function mockGetStudentPortrait(params: {
  university: string
  school?: string
  major?: string
  grade?: string
}) {
  if (params.school || params.major || params.grade) {
    return {
      code: 200,
      msg: '获取成功',
      data: {
        genderRatio: [
          { value: 666, name: '女生' },
          { value: 6666, name: '男生' }
        ]
      }
    }
  }

  return {
    code: 200,
    msg: '获取成功',
    data: {
      genderRatio: [
        { value: 1205, name: '女生' },
        { value: 1120, name: '男生' }
      ],
      politicalStatusRatio: [
        { value: 525, name: '党员' },
        { value: 800, name: '共青团员' },
        { value: 1000, name: '群众' }
      ],
      provinceRatio: [
        { value: 300, name: '浙江' },
        { value: 200, name: '河南' },
        { value: 150, name: '安徽' },
        { value: 180, name: '江西' },
        { value: 495, name: '其他' }
      ],
      inProvinceRatio: [
        { value: 30, name: '杭州' },
        { value: 100, name: '宁波' },
        { value: 50, name: '温州' },
        { value: 80, name: '嘉兴' },
        { value: 95, name: '绍兴' },
        { value: 45, name: '其他' }
      ],
      collegeCount: [
        { value: 370, name: '应用英语' },
        { value: 100, name: '计算机' },
        { value: 503, name: '土木' },
        { value: 830, name: '建筑' },
        { value: 925, name: '外贸' },
        { value: 415, name: '美学院' },
        { value: 215, name: '金融' },
        { value: 44, name: '旅游' },
        { value: 404, name: '国际' }
      ],
      studentDistributionRatio: [
        { value: 30, name: '应用英语' },
        { value: 100, name: '食品检验检测技术' },
        { value: 50, name: '大数据技术' },
        { value: 80, name: '关务与外贸服务' },
        { value: 95, name: '跨境电子商务' },
        { value: 45, name: '工业机器人技术' }
      ],
      studentComprehensiveEvaluationRatio1: [
        { name: '专业能力', max: 100 },
        { name: '实践能力', max: 100 },
        { name: '职业素养', max: 100 },
        { name: '核心素养', max: 100 },
        { name: '发展潜力', max: 100 }
      ],
      studentComprehensiveEvaluationRatio2: [
        {
          name: '最高分',
          value: [80, 70, 90, 85, 75]
        },
        {
          name: '最低分',
          value: [50, 55, 55, 50, 50]
        },
        {
          name: '平均分',
          value: [70, 65, 75, 70, 65]
        }
      ],
      studentComprehensiveEvaluationClassRanking: [
        { rank: 1, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 2, name: '海洋装备工程学院', major: '船舶电气工程技术', score: 375 },
        { rank: 3, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 4, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 5, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 6, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 7, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 8, name: '航海工程学院', major: '港口与航运管理', score: 418 },
        { rank: 9, name: '航海工程学院', major: '港口与航运管理', score: 418 }
      ],
      fivePerfectStudents: [
        { rank: 1, name: '李四', score: 95 },
        { rank: 2, name: '王五', score: 92 },
        { rank: 3, name: '张三', score: 90 },
        { rank: 4, name: '赵六', score: 88 },
        { rank: 5, name: '钱七', score: 85 },
        { rank: 6, name: '孙八', score: 82 }
      ],
      implementationCategoryRatio: [
        { value: 335, name: '升学' },
        { value: 310, name: '未落实' },
        { value: 234, name: '就业' },
        { value: 135, name: '创业' }
      ],
      jobCategoryRatio: [
        { value: 335, name: '软件' },
        { value: 310, name: '硬件' },
        { value: 234, name: '咨询' },
        { value: 135, name: '其他' }
      ],
      employmentTrendsRegion: [
        { value: 35, name: '上海' },
        { value: 28, name: '舟山' },
        { value: 42, name: '青岛' },
        { value: 32, name: '深圳' },
        { value: 26, name: '其他' }
      ],
      employmentTrendsIndustry: [
        { value: 35, name: '软件' },
        { value: 28, name: '硬件' },
        { value: 42, name: '咨询' },
        { value: 32, name: '其他' }
      ],
      employmentTrendsProfession: [
        { value: 35, name: '前端开发' },
        { value: 28, name: '后端开发' },
        { value: 42, name: '测试' },
        { value: 32, name: '运维' },
        { value: 26, name: '其他' }
      ],
      NatureOfTheContractingEntity: [320, 302, 301, 334],
      NatureOfTheContractingEntityXAxisData: ['国企', '外企', '民企', '事业单位'],

      postGraduationDestinationImplementationRate: [
        { value: 335, name: '已落实' },
        { value: 10, name: '未落实' }
      ],
      retentionRate: [
        { value: 335, name: '留舟' },
        { value: 30, name: '不留舟' }
      ],
      domesticAdmissionRate: [
        { value: 35, name: '国内升学' },
        { value: 310, name: '未升学' }
      ],
      rateOfGoingAbroad: [
        { value: 3, name: '已出国' },
        { value: 310, name: '未出国' }
      ]
    }
  }
}

export async function mockGetSchoolStructure(params: { university: string }) {
  if (params.university) {
    return {
      code: 200,
      msg: '获取成功',
      data: {
        schoolOptions: [
          { label: '学院一', value: 'school_1' },
          { label: '学院二', value: 'school_2' },
          { label: '学院三', value: 'school_3' }
        ],
        majorOptions: [
          { label: '专业一', value: 'major_1' },
          { label: '专业二', value: 'major_2' },
          { label: '专业三', value: 'major_3' }
        ],
        gradeOptions: [
          { label: '一年级', value: '1' },
          { label: '二年级', value: '2' },
          { label: '三年级', value: '3' },
          { label: '四年级', value: '4' }
        ]
      }
    }
  } else {
    return {
      code: 400,
      msg: '少传了大学名称参数'
    }
  }
}

export async function mockEmploymentDataAnalysis(params: { university: string }) {
  if(params.university)
  {
    return {
    code: 200,
    msg: '获取成功',
      data: {
        //四张卡片（大图表）数据
        employmentDataCards: [
          {
            value: 6986,
            percentage: 7.5,
            chartData: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            value: 6986,
            percentage: 6.5,
            chartData: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            value: 6986,
            percentage: 4.5,
            chartData: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            value: 6986,
            percentage: 2.5,
            chartData: [120, 132, 101]
          }
        ],
        //第二行折线图（多组数据）
        employmentDataMoreLineChart: [
          {
            name: '创业',
            data: [120, 132, 101, 134, 90, 130, 70, 82, 91, 104, 80, 90],
            stack: 'total'
          },
          {
            name: '就业',
            data: [80, 92, 71, 94, 60, 80 ,70, 82, 91, 104, 80, 90],
            stack: 'total'
          },
          {
            name: '升学',
            data: [70, 82, 91, 104, 80, 90, 80, 92, 71, 94, 60, 80],
            stack: 'total'
          }
        ],
        //第二行折线统计图（多组数据）x轴
        employmentDataMoreLineChartXAxisData: ['1月', '2月', '3月', '4月', '5月', '6月' ,'1月' , '2月', '3月', '4月', '5月', '6月'],

        //第二行table
        employmentDataTable1: [
          { rank: 1, name: '计算机学院', value: 1200 },
          { rank: 2, name: '电子信息学院', value: 1100 },
          { rank: 3, name: '自动化学院', value: 800 },
          { rank: 4, name: '机械工程学院', value: 600 },
          { rank: 5, name: '土木工程学院', value: 400 },
          { rank: 6, name: '艺术学院', value: 400 },
          { rank: 7, name: '旅游学院', value: 400 },
        ],
        //第三行环形图
        employmentDataPieChart1: [
          { value: 335, name: '升学' },
          { value: 310, name: '未落实' },
          { value: 234, name: '就业' },
          { value: 135, name: '创业' }
        ],
        //第三行水平柱状图
        employmentDataBarChart1: [50, 80, 120, 90, 60],
        employmentDataBarChart1XAxisData: ['产品A', '产品B', '产品C', '产品D', '产品E'],

        //第四行水平柱状图地区
        employmentDataBarChart2: [50, 80, 120, 90, 60],
        employmentDataBarChart2XAxisData: ['产品A', '产品B', '产品C', '产品D', '产品E'],
        //第四行水平柱状图行业
        employmentDataBarChart3: [50, 80, 120, 90, 60],
        employmentDataBarChart3XAxisData: ['产品A', '产品B', '产品C', '产品D', '产品E'],
        //第四行水平柱状图职业
        employmentDataBarChart4: [50, 80, 120, 90, 60],
        employmentDataBarChart4XAxisData: ['产品A', '产品B', '产品C', '产品D', '产品E'],
        //第四行table
        employmentDataTable2: [
          { rank: 1, name: '计算机学院', value: 1200 },
          { rank: 2, name: '电子信息学院', value: 1100 },
          { rank: 3, name: '自动化学院', value: 800 },
          { rank: 4, name: '机械工程学院', value: 600 },
          { rank: 5, name: '土木工程学院', value: 400 }
        ],
        //第五行柱状图（多组数据）
        employmentDataBarChart5: [
          {
            name: '销售额',
            data: [120, 200, 150, 80, 70, 110, 130]
          },
          {
            name: '利润',
            data: [20, 50, 30, 15, 10, 25, 35]
          }
        ],
        employmentDataBarChart5XAxisData: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
        //第五行柱状图省份比
        employmentDataBarChart6: [120, 200, 150, 80, 70, 110, 130],
        employmentDataBarChart6XAxisData: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],

        //第五行柱状图省内比
        employmentDataBarChart7: [220, 120, 150, 80, 70, 110, 130],
        employmentDataBarChart7XAxisData: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
      }
    }
  }else{
    return {
      code: 400,
      msg: '少传了大学名称参数'
    }
  }
  
}

// 可选：导出默认对象，便于引入
export default {
  mockLogin,
  mockGetUserInfo,
  mockGetStudentPortrait,
  mockGetSchoolTotal,
  mockGetSchoolStructure,
  mockEmploymentDataAnalysis
}
